-- 验证码识别
-- main.lua  

-- Create By TouchSpriteStudio on 00:17:50   
-- Copyright © TouchSpriteStudio . All rights reserved.
require('tsp')
require('ZZBase64')

function decodeURI(s)
    s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
    return s
end
function encodeURI(s)
    s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end)
    return string.gsub(s, " ", "+")
end

--新转译
function encodeURIs(s)
    s = string.gsub(s, "%+", function(c) return string.format("%%2b", string.byte(c)) end)
    return string.gsub(s, " ", "+")
end

function _getYzmAccount()
    local url = 'http://rok.honghongdesign.cn/public/';
    local postArr = {}
    postArr['s']="RokYzm.GetAccount"
    postArr['token'] = llsGameToken()[1]
    local data = post(url,postArr)
    if (data ) then
        return { data.data.st_username,data.data.st_password}
    end
end
	

function _yzmsb()
	require('tsp')
	init(1)
	local _time1 = os.time()
	local url = 'http://api.ttshitu.com/imageXYPlus'
	local st_account = _getYzmAccount()
-- 	st_account = {'ouwen000','AaDd112211..'}
	
	postData = {}
	postData['username'] = st_account[1]
	postData['password'] = st_account[2]
	postData['typeid'] = '27'
	postData['softid'] = '15ebbebcee0243eea1e5e93ee5160604'
-- 	postData['typename'] = '万国觉醒'

	snapshot("yzm.jpg", 400,21,934,640,0.5);
	path = userPath();
	ts = require('ts')
	ts.imgSize(path.."/res/yzm.jpg",path.."/res/yzm2.jpg",259,300)
	imagepath = path .. "/res/yzm2.jpg"
	require("ZZBase64")
	function base64s()
		local files
		local file = io.open(imagepath,"rb")
		if file then
			files = file:read("*a")
			file:close()
			return ZZBase64.encode(files);
		else
			return "";
		end
	end
	postData['image'] = base64s()
	local imgRes = post(url,postData)
	log(os.time()-_time1);

	if imgRes.message == 'success' then
		log('验证码结果为：'..imgRes.data.result )
		_app.yzmid = imgRes.data.id
		local _clickArr = strSplit(imgRes.data.result,"|");
		for i,v in ipairs(_clickArr) do
			_clickArr[i]= strSplit(v,",");
			click(_clickArr[i][1]*2+400+10,_clickArr[i][2]*2+21+10)
		end
		log(_clickArr)
		return true
	end
end


--  图鉴的高级算法
-- function _yzmsb()
-- 	require('tsp')
-- 	init(1)
-- 	local _time1 = os.time()
-- 	local url = 'http://api.ttshitu.com/imageXYPlus'
-- 	local st_account = _getYzmAccount()
-- 	postData = {}
-- 	postData['username'] = st_account[1]
-- 	postData['password'] = st_account[2]
-- 	postData['typeid'] = '47'
-- 	postData['softid'] = '15ebbebcee0243eea1e5e93ee5160604'
-- 	--postData['typename'] = '万国觉醒'
--     path = userPath();
--     imagepath = path .. "/res/yzm.jpg"
-- 	imagetitle = path .. "/res/yzmtitle.jpg"
	
-- 	snapshot("yzm.jpg", 400,105,933,638,0.5);
-- 	snapshot("yzmtitle.jpg", 687,20,942,101);
	
-- 	require("ZZBase64")
-- 	function base64s(imagepath)
-- 		local files
-- 		local file = io.open(imagepath,"rb")
-- 		if file then
-- 			files = file:read("*a")
-- 			file:close()
-- 			return ZZBase64.encode(files);
-- 		else
-- 			return "";
-- 		end
-- 	end
	
-- 	local t_img = {}
-- 	t_img['title_image'] = base64s(imagetitle)
-- 	local sz = require('sz')
-- 	local json = sz.json
-- 	postData['remark'] = json.encode(t_img)
-- 	postData['image'] = base64s(imagepath)
-- 	local imgRes = post(url,postData)
-- 	log(os.time()-_time1);

-- 	if imgRes.message == 'success' then
-- 		log('验证码结果为：'..imgRes.data.result )
-- 		_app.yzmid = imgRes.data.id
-- 		local _clickArr = strSplit(imgRes.data.result,"|");
-- 		for i,v in ipairs(_clickArr) do
-- 			_clickArr[i]= strSplit(v,",");
-- 			click(_clickArr[i][1]+400+5,_clickArr[i][2]+105+5)
-- 		end
-- 		log(_clickArr)
-- 		return true
-- 	end
-- end



-- 联众打码平台

-- function _yzmsb()
-- 	require('tsp')
-- 	init(1)
-- 	local _time1 = os.time()
-- 	local st_account = _getYzmAccount()
-- 	postData = {}
-- 	postData['username'] = st_account[1]
-- 	postData['password'] = st_account[2]
-- 	postData['typeid'] = '1307'
-- 	--postData['typename'] = '万国觉醒'
--     lz=require"lz"
--     lz.ocrInfo( postData['username'] ,postData['password'])
--     b=lz.ocrBalance()
--     log(b)
--     toast(b,0.5)
--     if tonumber(b)>0 then
--     	res,idorerr=lz.ocrScreen(400,21,934,640,postData['typeid'],60)
--     	if res then 
--     		log(res)
--     		local _clickArr = strSplit(res,"|");
--     		for i,v in ipairs(_clickArr) do
--     			_clickArr[i]= strSplit(v,",");
--     			click(_clickArr[i][1]+400+5,_clickArr[i][2]+21+5)
--     		end
--     		log(_clickArr)
--     		return true
--     	else
--     		log(idorerr)
--     		toast(idorerr,5)
--     	end
--     end
-- end


-- function DmGet(url)
-- 	local sz = require("sz")
-- 	local http = require("szocket.http")
-- 	local res, code = http.request(url);
-- 	if code == 200 then
-- 		local json = sz.json
-- 		if res ~= nil then
-- 			return res
-- 		end
-- 	end
-- end

-- function DmPost(url,arr)
-- 	log('tsp-post')
-- 	local sz = require("sz")
-- 	local cjson = sz.json
-- 	local http = sz.i82.http
-- 	local safari = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36'
-- 	local headers = {}
-- 	headers['User-Agent'] = safari
-- 	headers['Referer'] = url
-- -- 	headers['content-type'] = 'application/x-www-form-urlencoded'
-- 	headers['Content-Type'] = 'multipart/form-data; boundary=---------------------------7de3a916a0ab0'
-- 	headers_send = cjson.encode(headers)
-- 	post_send = cjson.encode(arr)
-- 	post_escaped = http.build_request(post_send)
-- 	log(post_send)
-- 	local status_resp, headers_resp, body_resp = http.post(url, 30, headers_send, post_escaped)
-- 	log(status_resp)
-- 	if status_resp == 200 then
-- 		log("body_resp")
-- 		log(body_resp)
-- 		log("headers_resp")
-- 		log(headers_resp)
-- 		if body_resp ~= 'timeout' then
-- 			local json = sz.json
-- 			return body_resp
-- -- 			return json.decode(body_resp)
-- 		else
-- 			log('超时了')
-- 		end
-- 	end
-- end


-- function _yzmsb()
-- 	require('tsp')
-- 	init(1)
-- 	local _time1 = os.time()
-- -- 	local st_account = _getYzmAccount()

--     path = userPath()
--     imagepath = path .. "/res/yzm.jpg"
--     snapshot("yzm.jpg", 374, 12,963, 747, 0.5)
    
--     require("ZZBase64")
-- 	function base64s(imagepath)
-- 		local files
-- 		local file = io.open(imagepath,"rb")
-- 		if file then
-- 			files = file:read("*a")
-- 			file:close()
-- 			return ZZBase64.encode(files);
-- 		else
-- 			return "";
-- 		end
-- 	end
    
-- 	postData = {}
-- 	postData['password'] = 'ouwen000|3A16D996BA0C00B7'
-- 	--postData['typename'] = '万国觉醒'

--     local imgRes = DmGet('http://3.haoi23.net/svlist.html')
--     imgRes = string.gsub(imgRes,'===','')
--     imgRes = string.gsub(imgRes,'+++','')
-- 	imgRes = split(imgRes,'--')
-- 	local url = 'http://'..imgRes[2]
	
-- 	imgBase64s = base64s(imagepath)
	
-- 	DmData = {}
-- 	DmData['userstr'] = 'ouwen000|3A16D996BA0C00B7'
-- 	DmData['gameid'] = 'X6004'
-- 	DmData['timeout'] = 60
-- 	DmData['rebate'] = '5916|F37C42FAD028AAE4'
-- 	DmData['daiLi'] = 'haoi'
-- 	DmData['kou'] = 100
-- 	DmData['beizhu'] = '%e5%a5%bd%e7%88%b1'
-- 	DmData['ver'] = 'web2'
-- 	DmData['key'] = os.time()
-- 	DmData['Img'] = encodeURI(imgBase64s)
	
-- 	log(url)
--     local imgRes = DmPost(url,DmData)
-- 	log( imgRes )
-- end


-- init(1)
-- _app = {}
-- _app.bid = 'com.lilithgames.rok.ios.offical'
-- -- require('token')
-- log( _yzmsb() )
-- log('end')


	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	